import request from '../utils/request'

/** 获取用户信息 */
function getUser(userId: number): Promise<DomoUser>
function getUser(userIdArray: number[]): Promise<DomoUser[]>
function getUser(userId: number | number[]): Promise<DomoUser | DomoUser[]> {
  if (typeof userId === 'number') {
    return request.get(`/users/${userId}`)
  } else {
    const params = { id: userId.join(',') }
    return request.get('/users', { params })
  }
}

export const userApi = {
  getUser,
  /** 获取用户列表 */
  getusers(params: any) {
    return request.get('/users', { params })
  },
  getJimengUsers(params: any) {
    return request.get('/users/jimeng', { params })
  },
  getJimengRank(params: any) {
    return request.get('/users/rank', { params })
  },
  /** 获取一个用户的粉丝, 不传第一个参数则获取当前登录用户的粉丝 */
  getUserFans(userId?: number, params: QueryParamsWithOffset = {}): Promise<DomoUser[]> {
    const url = userId ? `/users/${userId}/followers` : '/user/followers'
    return request.get(url, { params })
  },

  /** 获取一个用户正在关注的人, 不传第一个参数则获取当前登录用户关注的人 */
  getUserFollowing(userId?: number, params: QueryParamsWithOffset = {}): Promise<DomoUser[]> {
    const url = userId ? `/users/${userId}/followings` : '/user/followings'
    return request.get(url, { params })
  },

  /** 禁用用户 */
  deleteUser(userId: number) {
    return request.put(`/system/disabled/${userId}`)
  },

  /** 取消禁用用户 */
  deleteUserUp(userId: number) {
    return request.delete(`/system/disabled/${userId}`)
  },

  /** 关注一个用户 */
  followUser(userId: number) {
    return request.put(`/user/followings/${userId}`)
  },

  /** 取消关注一个用户 */
  unFollowUser(userId: number) {
    return request.delete(`/user/followings/${userId}`)
  },

  /** 更新用户信息 */
  saveUserInfo(payload: SaveUserInfoPayload) {
    return request.patch('/user', payload)
  },
  /** 更新用户手机号或者邮箱 */
  savePhoneOrMail(payload: SaveUserPhoneOrMail) {
    return request.put('/user', payload)
  },

  /** 保存用户认证 */
  saveVerification(payload: UpdateVerificationPayload) {
    return request.post('/user/verification', payload)
  },
  /** 更新用户认证 */
  updateVerification(payload: UpdateVerificationPayload) {
    return request.put('/user/verification', payload)
  },
  /** 删除用户认证 */
  deleteVerification() {
    return request.delete('/user/verification')
  },
  /** 获取积分流水 */
  getCurrencyOrders(params: GetCurrencyOrdersPayload = {}): Promise<DomoCurrencyOrder[]> {
    return request.get('/currency/orders', { params })
  },

  /**用户登录后获取首次奖励 */
  getLoginReward(): Promise<GetRewardReturns> {
    return request.put('/user/task/login')
  },
  /** 用户邀请的用户 */
  getInvitee(params: { offset: number; limit: number }): Promise<{ users: [] }> {
    return request.get('/user/invited-users', { params })
  },

  /** 设置邀请人 */
  setInvitee(payload: SetInvitee) {
    return request.patch('/user/inviter', payload)
  },

  /** 获取用户消息列表 */
  getNewsList() {
    return request.get('/user/notification-statistics')
  },

  /** (大概是)消除用户关注和粉丝的小红点 */
  setReaded(type: string) {
    return request.patch(`/user/counts?type=${type}`)
  },

  /** 获取用户未读消息列表 */
  getUnreadNewsList() {
    return request.get('/user/unread-count')
  },

  /** 获取用户收到的打赏type=reward,赞type=like, 评论type=comments */
  getUserNewsDetail(params?: GetCommentsParams): Promise<any> {
    return request.get(params?.type == 'answer' ? '/wenda-comments' : '/user/notifications', {
      params,
    })
  },

  /** 清除用户未读信息(消除消息页小红点) */
  removeUnreadTips(type: string) {
    return request.put(`/user/notifications?type=${type}`)
  },
  /** 获取被回答列表 */
  getUserAnswerList(params?: GetCommentsParams): Promise<any> {
    return request.get('/wenda-comments', { params })
  },
  /** 黑名单列表 */
  blacks(params: { limit: number; offset: number }): Promise<any> {
    return request.get('/user/blacks', { params })
  },
  /** 加入黑名单 */
  black(user: number): Promise<any> {
    return request.post(`/user/black/${user}`)
  },
  /** 移出黑名单 */
  unBlack(user: number): Promise<any> {
    return request.delete(`/user/black/${user}`)
  },
  /** 获取签到页面数据 */
  getSignInList() {
    return request.get(`/sign/signView`)
  },
  /** 今日是否签到 */
  isSignIn() {
    return request.get(`/sign/daySign`)
  },
  /** 签到 */
  addSignIn() {
    return request.post('/sign/add')
  },
  /** 获取用户排行榜(按积分) */
  getUserRanks(params: any) {
    return request.get('/user/currency/income-rank', { params })
  },
  /** 获取冠军榜用户 */
  getChampionUser(params: any) {
    // return request.get('/user/recommends', { params })
    return request.get('/user/getChampion', { params })
  },
  getRecommendUser(params: any) {
    // return request.get('/user/recommends', { params })
    return request.get('/user/getChampion', { params })
  },
  getBonusUser(params: any) {
    // return request.get('/user/recommends', { params })
    return request.get('/user/getBonusUser', { params })
  },
  getScoreUser(params: any) {
    // return request.get('/user/recommends', { params })
    return request.get('/user/getScoreUser', { params })
  },
  getSecondUser(params: any) {
    // return request.get('/user/recommends', { params })
    return request.get('/user/getSecondUser', { params })
  },
  getPersonMacthRecordList(params: any) {
    return request.get('/user/getPersonMatchRecordList', { params })
  },
  /** 获取活跃用户 */
  getActiveUser(params: any) {
    return request.get('/users', { params })
  },
  /** 获取同城用户 */
  getLocationUser(params: any) {
    return request.get('/user/nearby', { params })
  },
  /** 获取用户好友(相互关注的人) */
  getFriends(params: { offset?: number; limit?: 15; keyword?: string }) {
    return request.get('/user/follow-mutual', { params })
  },
  /** 获取会员配置 */
  getVipConfig(): Promise<DomoVip> {
    return request.get('/vip/configs')
  },
  /** 创建会员订单 */
  creatVipOrder(payload: CreateVipOrderPayload) {
    return request.post('/vip/orders', payload)
  },
  /** 会员转卡 */
  upVipLevel({ level = '' as string }) {
    return request.post('/vip/exchange-vip', { level })
  },
  /** 会员协议 */
  vipProtocol() {
    return request.get('/vip/protocol')
  },
  /** 用户/隐私协议 */
  showTerm(type: string) {
    return request.get(`/show-term?type=${type}`)
  },
  /** 需要用户处理的加圈申请 */
  joinTopicLogs(params: { exclude: string }) {
    return request.get('/user/feed-topics/logs-count', { params })
  },
  /** 获取当前登录用户的标签信息 */
  getUserTags() {
    return request.get('/user/tags')
  },
  /** 获取所有标签信息 */
  getTags() {
    return request.get('/tags')
  },
  /** 获取某个用户的标签信息 */
  getSomeoneTags(userId: number) {
    return request.get(`/users/${userId}/tags`)
  },
  /** 添加标签 */
  addTags(tagId: number) {
    return request.put(`/user/tags/${tagId}`)
  },
  /** 添加标签 */
  deletTags(tagId: number) {
    return request.delete(`/user/tags/${tagId}`)
  },
  /** 用户权限列表 */
  abilitiesList() {
    return request.get('/user/abilities')
  },
  /** 发起提现申请 */
  postWithdraw(payload: any) {
    return request.post('/plus-pay/cashes', payload)
  },
  /** 提现列表 */
  withdrawList(params: any) {
    return request.get('/plus-pay/cashes', { params })
  },
  /** 查找用户 */
  searchUser(params: any) {
    return request.get('/user/search', { params })
  },
  /** 获取用户圈子数 */
  getTopicsNum: (params: any) => request.get('/feed/topic/count', { params }),
  /** 获取IM的密码 */
  getImInfo: (): Promise<{ im_pwd_hash: any }> => request.get('/easemob/password'),
  /** 提现单个信息 */
  withdrawById(id: number) {
    return request.get(`/plus-pay/cashes/${id}`)
  },
  /** 意见反馈 */
  feedback({ content = '' as string }) {
    return request.post('/user/feedback', { content })
  },
}
